#include <GL/glut.h>
#include "draw.h"


void Draw::Missile(float x, float y , int mod)
{
	glPushMatrix();
	glTranslatef(x+15,y,0);
	glRotatef(60,0,1,0);
	glScalef(3,3,3);

	GLUquadric *cylindrQuad=gluNewQuadric();

	glColor3f(0.1,0.1,0.1);
	gluDisk(cylindrQuad,0,4,16,16);
	gluCylinder(cylindrQuad,4,1,5,16,16);

	glTranslatef(0,0,5);
	gluDisk(cylindrQuad,0,1,16,16);


	if(mod==0)
		glColor3f(0.6,0.2,0.2);
	else if(mod==1)
		glColor3f(0.2,0.2,0.6);
	else if(mod==2)
		glColor3f(0.2,0.6,0.2);
	glTranslatef(0,0,-15);
	gluDisk(cylindrQuad,0,2.5,16,16);
	gluCylinder(cylindrQuad,2.5,2.5,10,16,16);

	glPopMatrix();
}

void Draw::Mine(float x,float y)
{
	glColor3f(0.2,0.8,0.2);

	glPushMatrix();

	glTranslatef(x,y,0);
	glRotatef(270,1,0,0);
	glScalef(3,3,3);
	glutSolidSphere(5,16,16);
	glTranslatef(0,0,5);
	glutSolidSphere(1.5,16,16);

	glPopMatrix();
}


void Draw::Text(float x, float y, string text,int highlightPos,int size)
{
	if(x!=-1 || y!=-1)
		glRasterPos2f(x,y);

	int i=0;
	for (const char *p = text.c_str(); *p; p++,i++)
	{
		if(i==highlightPos)
			size++;
		if(size==0)
			glutBitmapCharacter(GLUT_BITMAP_8_BY_13 , *p);
		else if(size==1)
			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , *p);
		else if(size==2)
			glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12 , *p);
		else if(size==3)
			glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18 , *p);
		else if(size==4)
			glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24 , *p);
		if(i==highlightPos)
			size--;
	}
}


void Draw::Rectangle(float lowX,float lowY,float highX, float highY)
{
	glBegin(GL_QUADS);
	glVertex2f(lowX,highY);
	glVertex2f(highX,highY);
	glVertex2f(highX,lowY);
	glVertex2f(lowX,lowY);
	glEnd();
}

void Draw::FramedRectangle(float lowX,float lowY,float highX, float highY)
{

	glColor3f(1,1,1);
	glBegin(GL_QUADS);
		glVertex2f(lowX,highY);
		glVertex2f(highX,highY);
		glVertex2f(highX,lowY);
		glVertex2f(lowX,lowY);
	glEnd();

	glColor3f(0.5,0.5,0.5);
		glLineWidth(2.0f);
		glBegin(GL_LINES);
			glVertex2f(lowX+1,lowY-1);
			glVertex2f(lowX+1,highY);
			glVertex2f(lowX,highY);
			glVertex2f(highX+1,highY);
		glEnd();
		glColor3f(0.2,0.2,0.2);

		glBegin(GL_LINES);
			glVertex2f(highX,highY+1);
			glVertex2f(highX,lowY-1);
			glVertex2f(highX,lowY);
			glVertex2f(lowX-1,lowY);
		glEnd();
}

void Draw::Triangle(float x1,float y1,float x2,float y2,float x3,float y3)
{
	glColor3f(1,1,1);
	glBegin(GL_TRIANGLES);
	glVertex2f(x1,y1);
	glVertex2f(x2,y2);
	glVertex2f(x3,y3);
	glEnd();

	glColor3f(0.5,0.5,0.5);
	glLineWidth(2.0f);
	glBegin(GL_LINES);
		glVertex2f(x1,y1);
		glVertex2f(x2,y2);
		glVertex2f(x2,y2);
		glVertex2f(x3,y3);
	glEnd();
	glColor3f(0.2,0.2,0.2);

	glBegin(GL_LINES);
		glVertex2f(x3,y3);
		glVertex2f(x1,y1);
	glEnd();
}
